GDataManager    	= Packages.it.softphone.commons.gdata.GDataManager;
gdata           	= Packages.com.google.gdata.data;
ApplicationConfig   = Packages.it.softphone.spring.ApplicationConfig;


//
// example:
//	uploadDocument( "/",  "report.xsl", "reports", "myReport", "user", "password", ["user:share1@gmail.com", "user:share2@gmail.com"] );
//
function uploadDocument( sourcePath, sourceDoc, targetFolder, targetName,  username, password, shares ) {	

	var manager = GDataManager.createInstance( targetFolder, "http", "docs.google.com");

	manager.login( username, password );

	var sc = ApplicationConfig.getServletContext();
	
	var path = sc.getRealPath( sourcePath );

	var rpt = new java.io.File( path, sourceDoc);

	manager.service.setConnectTimeout( 30*1000 );
	manager.service.setReadTimeout( 30*1000 );
	
	var ref = manager.uploadDocument(rpt, targetName, null);

	if( ref!=null && shares!=null && shares.length>0) {

		var url = new java.net.URL(ref.getAclFeedLink().getHref());
		for( var i=0; i<shares.length; ++i ) {}
			manager.addShareReader( url, new java.net.URI(shares[i]));
		}
	}
		
	return ref.getDocumentLink();
}
